﻿using GDGeek;
using Microsoft.MixedReality.Toolkit.Experimental.UI;
using Microsoft.MixedReality.Toolkit.Utilities;
using MrPP.Helper;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

namespace MrPP.SerriedCabinet
{
    public class Menu : MonoBehaviour
    {
        [SerializeField]
        ScrollingObjectCollection _scrolling;
        [SerializeField]
        private MenuItem _phototype;
        [SerializeField]
        private List<MenuItem> _list = new List<MenuItem>();
        public void clear() {
            foreach (var item in _list) {
                GameObject.DestroyImmediate(item.gameObject);
            }
            _list.Clear();
          //  refresh();
        }
      
        [SerializeField]
        private ClippingBox _clipping = null;
        [SerializeField]
        private Transform _container = null;

        [SerializeField]
        private TextMeshPro _title;
        public string title { 
            set {
                _title.text = value;
            } 
        }

        public void addItem(int index, CabinetGroup.ItemData data)
        {
            MenuItem item = GameObject.Instantiate(_phototype);

            IntId id = item.gameObject.AskComponent<IntId>();
            id.value = index;
            item.gameObject.SetActive(true);
            item.transform.SetParent(_container, false);
            item.setup(data, _list.Count);
            

            _list.Add(item);
        }

        public void refresh() {
            _clipping.ClearRenderers();
            _scrolling.UpdateCollection();
        }


    }
}